package com.ruoyi.place.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.place.domain.bo.PlaceEzdhxpqyBo;
import com.ruoyi.place.domain.vo.PlaceEzdhxpqyVo;
import com.ruoyi.place.service.IPlaceEzdhxpqyService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 易制毒化学品企业
 *
 * @author xiaohao
 * @date 2023-01-19
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/place/ezdhxpqy")
public class PlaceEzdhxpqyController extends BaseController {

    private final IPlaceEzdhxpqyService iPlaceEzdhxpqyService;

    /**
     * 查询易制毒化学品企业列表
     */
    @GetMapping("/list")
    public TableDataInfo<PlaceEzdhxpqyVo> list(PlaceEzdhxpqyBo bo, PageQuery pageQuery) {
        return iPlaceEzdhxpqyService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出易制毒化学品企业列表
     */
    @Log(title = "易制毒化学品企业", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(PlaceEzdhxpqyBo bo, HttpServletResponse response) {
        List<PlaceEzdhxpqyVo> list = iPlaceEzdhxpqyService.queryList(bo);
        ExcelUtil.exportExcel(list, "易制毒化学品企业", PlaceEzdhxpqyVo.class, response);
    }

    /**
     * 获取易制毒化学品企业详细信息
     *
     * @param ezdhxpqyId 主键
     */
    @GetMapping("/{ezdhxpqyId}")
    public R<PlaceEzdhxpqyVo> getInfo(@NotNull(message = "主键不能为空")
                                      @PathVariable Long ezdhxpqyId) {
        return R.ok(iPlaceEzdhxpqyService.queryById(ezdhxpqyId));
    }

    /**
     * 新增易制毒化学品企业
     */
    @Log(title = "易制毒化学品企业", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody PlaceEzdhxpqyBo bo) {
        return toAjax(iPlaceEzdhxpqyService.insertByBo(bo));
    }

    /**
     * 修改易制毒化学品企业
     */
    @Log(title = "易制毒化学品企业", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody PlaceEzdhxpqyBo bo) {
        return toAjax(iPlaceEzdhxpqyService.updateByBo(bo));
    }

    /**
     * 删除易制毒化学品企业
     *
     * @param ezdhxpqyIds 主键串
     */
    @Log(title = "易制毒化学品企业", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ezdhxpqyIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ezdhxpqyIds) {
        return toAjax(iPlaceEzdhxpqyService.deleteWithValidByIds(Arrays.asList(ezdhxpqyIds), true));
    }
}
